class Promise {
  constructor(executor) {
    this.reason = null;
    this.status = "PENDING";
    this.value = null;
    const resolve = () => {};
    const reject = () => {};
    executor(resolve, reject);
  }

  then(onFulFilled, onRejected) {
    if (typeof onFulFilled !== 'function') {
      onFulFilled = v => v;
    }
    if (typeof onRejected !=='function') {
      onRejected = err => {
        throw err;
      }
    }

    if (this.status === 'PENDING') {
      onFulFilled(this.value)
    }

    if (this.status === 'RESOLVED') {
      onRejected(this.reason)
    }
  }
}
